Skip to content

Fix n+1 query #6549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2025
Merged

Fix n+1 query #6549

merged 1 commit into from
Mar 10, 2025

Conversation

smithellis
Copy link
Contributor

In this part of the code:

for obj in objects: question = obj.content_object obj.available_topics = get_hierarchical_topics(question.product) obj.available_tags = available_tags obj.saved_tags = question.tags.values_list("id", flat=True)

We had obj.saved_tags executing a query for each questions tags. Now we prefetch_related in the initial query and hopefully avoid.

@smithellis smithellis marked this pull request as ready for review March 10, 2025 17:32
@smithellis smithellis merged commit b9ff160 into mozilla:main Mar 10, 2025
2 checks passed
@smithellis smithellis deleted the slow-or-500-at-moderate branch March 10, 2025 17:58
@mozilla mozilla deleted a comment from miorahmadhidayat Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants